package com.example.happiness.service.general.Impl;

import com.example.happiness.constant.Message;
import com.example.happiness.mapper.ChatMapper;
import com.example.happiness.pojo.Chat;
import com.example.happiness.service.general.ChatService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.util.Objects;

@Service
public class ChatServiceImpl implements ChatService {
    @Autowired
    ChatMapper chatMapper;

    public void addChat(Chat chat) {
        if(chat.getAdmintype()!=null){
            if(Objects.equals(chat.getAdmintype(), Message.RIGHT)){
                chat.setUsertype(Message.LEFT);
                chat.setTime(LocalDateTime.now());
                chatMapper.insert(chat);
            }
        }
        if (chat.getUsertype()!=null){
            if(Objects.equals(chat.getUsertype(), Message.RIGHT)){
                chat.setAdmintype(Message.LEFT);
                chat.setTime(LocalDateTime.now());
                chatMapper.insert(chat);
            }
        }
    }
}
